package org.examples;

import io.netty.handler.codec.http.HttpHeaderNames;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.netty.ByteBufFlux;
import reactor.netty.http.client.HttpClient;

import static org.examples.DebugConstants.host;
import static org.examples.DebugConstants.isHttpbin;
import static org.examples.DebugConstants.nttsJson;
import static org.examples.DebugConstants.nttsPath;

@Slf4j
public class ReactorNtts {
  public static void main(final String[] args) throws Exception {
    log.info("ReactorNtts.main");
    HttpClient client = HttpClient.create().baseUrl(host);
    if (!isHttpbin()) {
      client = client.secure();
    }
    client.headers(headers -> {
          headers.set(HttpHeaderNames.CONTENT_TYPE, "application/json");
        })
        .post()               // Specifies that POST method will be used
        .uri(nttsPath())   // Specifies the path
        .send(ByteBufFlux.fromString(Flux.just(nttsJson)))  // Sends the request body
        .responseContent()    // Receives the response body
        //        .aggregate()
        //        .asString()
        .log("http-client")
        .blockLast();
  }
}
